#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
#import <CoreLocation/CoreLocation.h>

@interface AppDelegate () <CLLocationManagerDelegate>

@property (nonatomic, strong) CLLocationManager *locationManager;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  [self initLocation];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)initLocation {
    
    self.locationManager = [CLLocationManager new];
    self.locationManager.delegate = self;
    [self.locationManager requestAlwaysAuthorization];
    // [self.locationManager requestWhenInUseAuthorization];
    @try {
        // 后台定位依然可用
       self.locationManager.allowsBackgroundLocationUpdates = YES;
    } @catch (NSException *exception) {
        NSLog(@"异常：%@", exception);
    } @finally {
        
    }
    [self.locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
    
    NSLog(@"%s：位置信息：%@", __FUNCTION__, locations);
}

@end
